package com.chen.demo.rhombus.ohs.local.pl.executor;

import com.chen.demo.rhombus.domain.dto.UserDto;
import com.chen.demo.rhombus.domain.service.UserService;
import com.chen.demo.rhombus.ohs.local.pl.command.UserAddCommand;
import com.chen.winnerframework.cqrs.executor.CommandExecutor;
import com.chen.winnerframework.http.response.Response;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

@Component
@RequiredArgsConstructor
public class UserAddCmdExe implements CommandExecutor<UserAddCommand, Response> {

    private final UserService userService;

    @Override
    public Response execute(UserAddCommand command) {
        UserDto userDto = command.to(UserDto.class);
        userService.saveUser(userDto);
        return Response.success();
    }

}
